package cn.iocoder.yudao.module.ai.service.algorithmlibrary;


import org.springframework.stereotype.Service;
import javax.annotation.Resource;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import cn.iocoder.yudao.module.ai.controller.admin.algorithm.vo.*;
import cn.iocoder.yudao.module.ai.dal.dataobject.algorithmlibrary.AlgorithmLibraryDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ai.dal.mysql.algorithmlibrary.AlgorithmLibraryMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 推理算法库 Service 实现类
 *
 * @author 侯俊青
 */
@Service
@Validated
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class AlgorithmLibraryServiceImpl implements AlgorithmLibraryService {



    @Resource
    private AlgorithmLibraryMapper algorithmLibraryMapper;

    @Override
    public Long createAlgorithmLibrary(AlgorithmLibrarySaveReqVO createReqVO) {
        // 插入
        AlgorithmLibraryDO algorithmLibrary = BeanUtils.toBean(createReqVO, AlgorithmLibraryDO.class);
        algorithmLibraryMapper.insert(algorithmLibrary);
        // 返回
        return algorithmLibrary.getId();
    }

    @Override
    public void updateAlgorithmLibrary(AlgorithmLibrarySaveReqVO updateReqVO) {
        // 更新
        AlgorithmLibraryDO updateObj = BeanUtils.toBean(updateReqVO, AlgorithmLibraryDO.class);
        algorithmLibraryMapper.updateById(updateObj);
    }

    @Override
    public void deleteAlgorithmLibrary(Long id) {
        // 删除
        algorithmLibraryMapper.deleteById(id);
    }



    @Override
    public AlgorithmLibraryDO getAlgorithmLibrary(Long id) {
        return algorithmLibraryMapper.selectById(id);
    }




    @Override
    public PageResult<AlgorithmLibraryDO> getAlgorithmLibraryPage(AlgorithmLibraryPageReqVO pageReqVO) {

        return algorithmLibraryMapper.selectPage(pageReqVO);
    }

}